package com.ruoyi.web.controller.ltd_web;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.ltd_web.domain.dto.LtdProductDetailItemDto;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ltd_web.domain.LtdProductDetailItem;
import com.ruoyi.ltd_web.service.ILtdProductDetailItemService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 产品资料明细项Controller
 *
 * @author ruoyi
 * @date 2025-03-17
 */
@RestController
@RequestMapping("/system/ltd_product_detail_item")
public class LtdProductDetailItemController extends BaseController
{
    @Autowired
    private ILtdProductDetailItemService ltdProductDetailItemService;

    /**
     * 查询产品资料明细项列表
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('system:item:list')")
    @GetMapping("/list")
    public TableDataInfo list(LtdProductDetailItem ltdProductDetailItem)
    {
        startPage();
        List<LtdProductDetailItem> list = ltdProductDetailItemService.selectLtdProductDetailItemList(ltdProductDetailItem);
        return getDataTable(list);
    }

    /**
     * 导出产品资料明细项列表
     */
//    @PreAuthorize("@ss.hasPermi('system:item:export')")
    @Log(title = "产品资料明细项", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LtdProductDetailItem ltdProductDetailItem)
    {
        List<LtdProductDetailItem> list = ltdProductDetailItemService.selectLtdProductDetailItemList(ltdProductDetailItem);
        ExcelUtil<LtdProductDetailItem> util = new ExcelUtil<LtdProductDetailItem>(LtdProductDetailItem.class);
        util.exportExcel(response, list, "产品资料明细项数据");
    }

    /**
     * 获取产品资料明细项详细信息
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('system:item:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(ltdProductDetailItemService.selectLtdProductDetailItemById(id));
    }

    /**
     * 新增产品资料明细项
     */
    @PreAuthorize("@ss.hasPermi('system:item:add')")
    @Log(title = "产品资料明细项", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LtdProductDetailItem ltdProductDetailItem)
    {
        return toAjax(ltdProductDetailItemService.insertLtdProductDetailItem(ltdProductDetailItem));
    }

    /**
     * 修改产品资料明细项
     */
    @PreAuthorize("@ss.hasPermi('system:item:edit')")
    @Log(title = "产品资料明细项", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LtdProductDetailItem ltdProductDetailItem)
    {
        return toAjax(ltdProductDetailItemService.updateLtdProductDetailItem(ltdProductDetailItem));
    }

    /**
     * 删除产品资料明细项
     */
    @PreAuthorize("@ss.hasPermi('system:item:remove')")
    @Log(title = "产品资料明细项", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ltdProductDetailItemService.deleteLtdProductDetailItemByIds(ids));
    }

    /**
     * 新增产品资料明细项
     */
    @Log(title = "新增产品资料明细项", businessType = BusinessType.INSERT)
    @PostMapping("/addLtdProductDetailItem")
    public AjaxResult addLtdProductDetailItem(@ModelAttribute LtdProductDetailItemDto ltdProductDetailItemDto)
    {
        return ltdProductDetailItemService.addLtdProductDetailItem(ltdProductDetailItemDto);
    }

    /**
     * 修改产品资料明细项
     */
    @Log(title = "修改产品资料明细项", businessType = BusinessType.UPDATE)
    @PutMapping("/updateDetailItem")
    public AjaxResult updateDetailItem(@ModelAttribute LtdProductDetailItemDto ltdProductDetailItemDto)
    {
        return ltdProductDetailItemService.updateDetailItem(ltdProductDetailItemDto);
    }

    /**
     * 删除产品资料明细项
     */
    @Log(title = "删除产品资料明细项", businessType = BusinessType.DELETE)
    @DeleteMapping("/deleteLtdProductDetailItem/{ids}")
    public AjaxResult deleteLtdProductDetailItem(@PathVariable Long[] ids)
    {
        return ltdProductDetailItemService.deleteLtdProductDetailItem(ids);
    }

    /**
     * 获取产品资料详细信息
     */
    @Anonymous
    @GetMapping(value = "/getItemList/{detailId}")
    public AjaxResult getItemList(@PathVariable("detailId") Long detailId)
    {
        return ltdProductDetailItemService.getItemList(detailId);
    }

}
